/*    */ package com.hp.bon.sgw.scsp;
/*    */ 
/*    */ import java.nio.charset.Charset;
/*    */ import java.nio.charset.CharsetDecoder;
/*    */ import org.apache.mina.core.buffer.IoBuffer;
/*    */ import org.apache.mina.core.session.IoSession;
/*    */ import org.apache.mina.filter.codec.ProtocolDecoderOutput;
/*    */ import org.apache.mina.filter.codec.demux.MessageDecoder;
/*    */ import org.apache.mina.filter.codec.demux.MessageDecoderResult;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ 
/*    */ public class SCSPMessageDecoder
/*    */   implements MessageDecoder
/*    */ {
/* 40 */   private static final Logger LOGGER = LoggerFactory.getLogger(SCSPMessageDecoder.class);
/* 41 */   private int length = 0;
/* 42 */   private byte version = -1;
/*    */ 
/*    */   public MessageDecoderResult decodable(IoSession session, IoBuffer in) {
/* 45 */     if (in.remaining() < 8) {
/* 46 */       return MessageDecoderResult.NEED_DATA;
/*    */     }
/* 48 */     this.length = in.getInt();
/* 49 */     if ((this.length > 8) && (this.length <= 10485760))
/*    */     {
/* 51 */       this.version = in.get();
/* 52 */       if (this.version == SCSPMessage.VERSION)
/*    */       {
/* 54 */         return MessageDecoderResult.OK;
/*    */       }
/*    */ 
/* 58 */       return MessageDecoderResult.NOT_OK;
/*    */     }
/*    */ 
/* 62 */     return MessageDecoderResult.NOT_OK;
/*    */   }
/*    */ 
/*    */   public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
/*    */     throws Exception
/*    */   {
/* 68 */     if (in.remaining() >= this.length)
/*    */     {
/* 70 */       in.getInt();
/* 71 */       in.getInt();
/* 72 */       Charset charset = Charset.forName("UTF-8");
/* 73 */       CharsetDecoder decoder = charset.newDecoder();
/* 74 */       String strBuf = in.getString(this.length - 8, decoder);
/* 75 */       SCSPMessage m = new SCSPMessage(strBuf);
/* 76 */       m.setLength(this.length);
/* 77 */       m.setVersion(this.version);
/* 78 */       out.write(m);
/*    */     }
/*    */     else
/*    */     {
/* 82 */       return MessageDecoderResult.NEED_DATA;
/*    */     }
/* 84 */     return MessageDecoderResult.OK;
/*    */   }
/*    */ 
/*    */   protected SCSPMessage decodeBody(IoSession session, IoBuffer in)
/*    */   {
/* 93 */     return null;
/*    */   }
/*    */ 
/*    */   public void finishDecode(IoSession session, ProtocolDecoderOutput out)
/*    */     throws Exception
/*    */   {
/*    */   }
/*    */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.sgw.scsp.SCSPMessageDecoder
 * JD-Core Version:    0.6.1
 */